package com.team.arms.political.controller;

import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.political.domain.vo.Messagevo;
import com.team.arms.political.mapper.PoliReviewInfoMapper;
import com.team.arms.political.service.PoliReviewInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author huazige
 * @Date 2022/5/9 15:29
 * @Version 1.0
 */
@RequestMapping("/message")
@RestController
@CrossOrigin
@Api(tags = "政治考核-材料代收+已收")
public class MessageController {

    /**
     * 查询所有政审中的信息
     */

    @Autowired
    PoliReviewInfoService poliReviewInfoService;
    @Resource
    PoliReviewInfoMapper poliReviewInfoMapper;


    @ApiOperation("查询未收")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/ready")
    public AjaxResult getmsgready() {
        String paperStatus ="未回收";
        List<Messagevo> list = poliReviewInfoMapper.selectmsg(paperStatus);
//
        if (list!=null){
            return AjaxResult.success("查询成功",list) ;
        }
        else {
            return AjaxResult.error("查询失败");
        }


    }
    @ApiOperation("查询已收")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/already")
    public AjaxResult getmsgalrady() {
         String paperStatus ="已回收";
        List<Messagevo> list = poliReviewInfoMapper.selectmsg(paperStatus);
//
        if (list!=null){
            return AjaxResult.success("查询成功",list) ;
        }
        else {
            return AjaxResult.error("查询失败");
        }


    }


    @ApiOperation(value = "未收-姓名查找")
    @PostMapping("/found")
    //
//    三张表的数据，删除的时候，直接这三个都删除
    public AjaxResult found( @RequestParam("name")String name) {
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据
        String paperStatus ="未回收";
        List<Messagevo> list = poliReviewInfoMapper.selectmsgbyname(paperStatus,name);
        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到该人未收材料信息");
        }

    }
    @ApiOperation(value = "已收-姓名查找")
    @PostMapping("/find")
    //
//    三张表的数据，删除的时候，直接这三个都删除
    public AjaxResult find( @RequestParam("name")String name) {
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据
        String paperStatus ="已回收";

        List<Messagevo> list = poliReviewInfoMapper.selectmsgbyname(paperStatus,name);
        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到该人已收材料信息");
        }

    }
    @ApiOperation(value = "代收材料-材料已收功能(单个和批量都可以)")
    @PostMapping ("/take")
    /*三张表的数据，删除的时候，直接这三个都删除*/
    public AjaxResult take( @RequestParam("poliInfoId")List<String> poliInfoIds) {
        boolean b=false;
        String paperStatus ="未回收";
        List<Messagevo> list = poliReviewInfoMapper.selectmsg(paperStatus);
        for (String poliInfoId: poliInfoIds
             ) {
            b =    poliReviewInfoMapper.updatemsgById(poliInfoId);
        }


        return b ? AjaxResult.success("材料回收成功") : AjaxResult.error("材料回收失败");
    }
    @ApiOperation("导出代收")
    @GetMapping("/exportready")
    public void export(HttpServletResponse response)
    {     String paperStatus ="未回收";
        List<Messagevo> list = poliReviewInfoMapper.selectmsg(paperStatus);
        poliReviewInfoService.exportpoli(response,list,Messagevo.class,"代收材料信息表");


    }
    @ApiOperation("导出已收")
    @GetMapping("/exportalr")
    public void export2(HttpServletResponse response)
    {     String paperStatus ="已回收";
        List<Messagevo> list = poliReviewInfoMapper.selectmsg(paperStatus);
        poliReviewInfoService.exportpoli(response,list,Messagevo.class,"已收材料信息表");


    }
}
